package com.ant.game.chess01;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TextView;

public class Chess extends AppCompatActivity {
    private ChessView myChessView;
    private String Tag = "chess";
    private TextView myTextView;
    final int MENU_START = Menu.FIRST;
    final int MENU_RED = Menu.FIRST + 1;
    final int MENU_BLACK = Menu.FIRST + 2;
    final int MENU_HELP = Menu.FIRST + 3;


    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        myChessView = (ChessView) findViewById(R.id.myChessView);

        myChessView.setTv((TextView) findViewById(R.id.myTextView));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, MENU_START, 0, "开始游戏");
        menu.add(0, MENU_RED, 0, "选择红方");
        menu.add(0, MENU_BLACK, 0, "选择黑方");
        menu.add(0, MENU_HELP, 0, "游戏帮助");
        return true;
        //return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case MENU_START:
                myChessView.setMyColor(ChessView.red);
                myChessView.initGame();
                myChessView.invalidate();
                break;
            case MENU_RED:
                myChessView.setMyColor(ChessView.red);
                myChessView.initGame();
                myChessView.invalidate();
                break;
            case MENU_BLACK:
                myChessView.setMyColor(ChessView.black);
                myChessView.initGame();
                myChessView.setComputer(true);
                myChessView.computerMoveChess();
                break;
            case MENU_HELP:
                showHelpDialog();
                break;
        }
        return false;
    }

    private void showHelpDialog() {
        new AlertDialog.Builder(this)
                .setTitle("游戏帮助")
                .setMessage("规则:每次红方棋子先走\n使用上下左右键移动\n中间键确认落子")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {


                    }

                }).show();

    }
}